/*
 *  $TEAM_NAME Space Trader
 */
package views;

import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.Dimension;

/**
 * For the title panel panel.
 * @author twb
 * @version 1.0
 */
public class TitlePanel extends JPanel {
	/**
	 * field
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * field
	 */
	private final JPanel splash;
	
	/**
	 * field
	 */
	private final JButton newButton;
	
	/**
	 * field
	 */
	private final JButton loadButton;
	
	/**
	 * Create the panel.
	 */
	public TitlePanel() {
		super.setLayout(null);

		newButton = new JButton("New");
		super.add(newButton);
		
		loadButton = new JButton("Load");
		super.add(loadButton);
			
		splash = new SplashPanel();
		super.add(splash);
	
		super.validate();
	}

	/**
	 * Used to change the size of the title panel
	 * @param x
	 * @param y
	 * @param width
	 * @param height
	 */
	@Override
    public void setBounds(int x, int y, int width, int height) {
        super.setBounds(x, y, width, height);
        layoutSubviews();
    }

	/**
	 * new button x coordinate 
	 */
	private static final int NEWBUTTONWIDTHWISESTARTPLACE = 10;
	
	/**
	 * new button y coordinate 
	 */
	private static final int NEWBUTTONHEIGHTWISESTARTPLACE = 50;
	
	/**
	 * new button width coordinate 
	 */
	private static final int NEWBUTTONWIDTH = 20;
	
	/**
	 * new button height coordinate 
	 */
	private static final int NEWBUTTONHEIGHT = 40;
	
	/**
	 * load button x coordinate 
	 */
	private static final int LOADBUTTONWIDTHWISESTARTPLACE = 10;
	
	/**
	 * load button y coordinate 
	 */
	private static final int LOADBUTTONHEIGHTWISESTARTPLACE = 50;
	
	/**
	 * load button width coordinate 
	 */
	private static final int LOADBUTTONWIDTH = 20;
	
	/**
	 * load button height coordinate 
	 */
	private static final int LOADBUTTONHEIGHT = 40;
	
	/**
	 * Layouts subviews
	 */
    public void layoutSubviews() {
        final Dimension size = getSize();

        splash.setBounds(0, 0, size.width, size.height);
        newButton.setBounds(NEWBUTTONWIDTHWISESTARTPLACE, 
        		size.height - NEWBUTTONHEIGHTWISESTARTPLACE, 
        		(size.width >> 1) - NEWBUTTONWIDTH, NEWBUTTONHEIGHT);
        loadButton.setBounds((size.width >> 1) 
        		+ LOADBUTTONWIDTHWISESTARTPLACE, 
        		size.height - LOADBUTTONHEIGHTWISESTARTPLACE, 
        		(size.width >> 1) - LOADBUTTONWIDTH, LOADBUTTONHEIGHT);
    }

    /**
     * Adds a listener for updates.
     * @param listener
     */
    public void addActionListener(ActionListener listener) {
        newButton.addActionListener(listener);
        loadButton.addActionListener(listener);
    }
}
